<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>员工管理 - HRMS</title>
    <jsp:include page="../../include/head.jsp"/>
</head>
<body>
    <jsp:include page="../../include/header.jsp"/>
    
    <div class="container mt-4">
        <!-- 面包屑导航 -->
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/auth/index">首页</a></li>
                <li class="breadcrumb-item active" aria-current="page">员工管理</li>
            </ol>
        </nav>

        <!-- 错误信息显示 -->
        <c:if test="${not empty error}">
            <div class="alert alert-danger" role="alert">
                ${error}
            </div>
        </c:if>

        <!-- 成功信息显示 -->
        <c:if test="${not empty success}">
            <div class="alert alert-success" role="alert">
                ${success}
            </div>
        </c:if>

        <!-- 功能按钮 -->
        <div class="row mb-3">
            <div class="col">
                <a href="${pageContext.request.contextPath}/hr/employee/add" class="btn btn-primary">
                    <i class="fas fa-plus"></i> 添加员工
                </a>
            </div>
        </div>

        <!-- 员工列表 -->
        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                            <tr>
                                <th>员工ID</th>
                                <th>姓名</th>
                                <th>部门</th>
                                <th>职位</th>
                                <th>入职日期</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${employees}" var="emp">
                                <tr>
                                    <td>${emp.empId}</td>
                                    <td>${emp.empName}</td>
                                    <td>${emp.orgId}</td>
                                    <td>${emp.getRoleName()}</td>
                                    <td><fmt:formatDate value="${emp.empEntryDate}" pattern="yyyy-MM-dd"/></td>
                                    <td>
                                        <span class="badge ${emp.isActive() ? 'bg-success' : 'bg-danger'}">
                                            ${emp.isActive() ? '在职' : '离职'}
                                        </span>
                                    </td>
                                    <td>
                                        <div class="btn-group">
                                            <a href="${pageContext.request.contextPath}/hr/employee/detail/${emp.empId}" 
                                               class="btn btn-sm btn-info">
                                                <i class="fas fa-info-circle"></i> 详情
                                            </a>
                                            <a href="${pageContext.request.contextPath}/hr/employee/edit/${emp.empId}" 
                                               class="btn btn-sm btn-primary">
                                                <i class="fas fa-edit"></i> 修改
                                            </a>
                                            <c:if test="${emp.isActive()}">
                                                <a href="${pageContext.request.contextPath}/hr/employee/terminate/${emp.empId}" 
                                                   class="btn btn-sm btn-danger">
                                                    <i class="fas fa-user-times"></i> 离职
                                                </a>
                                            </c:if>
                                        </div>
                                    </td>
                                </tr>
                            </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <jsp:include page="/WEB-INF/jsp/include/footer.jsp"/>
</body>
</html>
